<%
  if controller.java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'updatable_key')
    has_modules = !@project.modules.empty?
    reset_cycle 'modules_tree'
%>

<script type="text/javascript">
  function update_launched() {
    $j('input.action').each(function(index,input) {
      input.disabled=true;
    });
  }
</script>

<h1 class="admin-page-title"><%= message('update_key.page') -%></h1>
<p class="admin-page-description"><%= message('update_key.page.description') -%></p>

<% if has_modules %>
  <h2><%= message('update_key.bulk_update') -%></h2>
  <br/>
  <p>
    <%= message('update_key.bulk_change_description') -%>
    <br/><br/>
    <%= message('update_key.current_key_for_project_x_is_x', :params => [@project.name, @project.key]) -%>
  </p>
  <br/>
  <% form_tag( {:action => 'prepare_key_bulk_update', :id => @project.id }, :onsubmit => "update_launched();$j('#loading_bulk_update').show();") do -%>
    <table>
      <tr>
        <td style="padding-right: 20px"><%= message('update_key.replace') -%>:</td>
        <td><input type="text" value="" name="string_to_replace" id="string_to_replace" size="40"></td>
        <td class="form-val-note" style="padding-left: 10px;"><%= message('update_key.replace_example') -%></td>
      </tr>
      <tr>
        <td style="padding-right: 20px"><%= message('update_key.by') -%>:</td>
        <td><input type="text" value="" name="replacement_string" id="replacement_string" size="40"></td>
        <td class="form-val-note" style="padding-left: 10px;"><%= message('update_key.by_example') -%></td>
      </tr>
      <tr>
        <td></td>
        <td style="padding-top: 5px">
          <%= submit_tag message('update_key.rename'), :id => 'bulk_update_button', :class => 'action' -%>
          <span class="loading" id="loading_bulk_update" style="display: none; padding: 3px 10px;"></span>
        </td>
        <td></td>
      </tr>
    </table>
  <% end %>
  <br/>
  <br/>
  <h2><%= message('update_key.fine_grained_key_update') -%></h2>
  <br/>
<% end %>

  <table class="data" style="width:1%">
    <thead>
      <tr>
        <th class="nowrap"><%= message('update_key.old_key') -%></th>
        <th><%= message('update_key.new_key') -%></th>
      </tr>
    </thead>
    <tbody>
      <%= render :partial => 'key_modules', :locals => {:current_module => @project, :module_depth => 0, :id_prefix => "0"} -%>
    </tbody>
  </table>

<% end %>
